package com.kaesar.leetcode.LeetCode_251_300;

public class LeetCode_258 {
    public static int addDigits(int num) {
        // 最后的返回值
        int result = num;
        while (result >= 10) {
            int temp = 0;
            // 各个数位相加
            while (result > 10) {
                temp += result % 10;
                result = result / 10;
            }
            if (result == 10) {
                temp += 1;
            } else {
                temp += result;
            }
            result = temp;
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(addDigits(385));
    }
}
